<template>
  <div class="base-container">
    <el-form
      ref="toolQuery"
      :model="toolQuery"
      :rules="toolQueryRules"
      size="small"
      label-width="120px"
      v-show="toolQueryVisiable"
    >
      <el-row>
        <el-col :span="6">
          <el-form-item label="账户名：" prop="username" label-width="70px">
            <el-input
              v-model="toolQuery.username"
              placeholder="请输入账户名："
              clearable
              :style="{ width: '100%' }"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="接口路由" prop="actionKey">
            <el-input
              v-model="toolQuery.actionKey"
              placeholder="请输入接口路由"
              clearable
              :style="{ width: '100%' }"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5" :offset="1">
          <el-button type="primary" @click="initData" size="small"
            >提交</el-button
          >
          <el-button @click="resetForm" size="small">重置</el-button>
        </el-col>
      </el-row>
    </el-form>

    <toolBar
      :tableColumnConfig="tableColumnConfig"
      :checkedRow="checkedRow"
      :dataList="dataList"
      :toolBarAddBTN="toolBarAddBTN"
      @edit="edit"
      @del="del"
    ></toolBar>
    <el-table
      height="800"
      v-loading="tableLoading"
      :data="processData"
      style="width: 100%"
      @selection-change="selectionChangeHandle"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column type="expand">
        <template slot-scope="scope">
          <pre>{{ scope.row.detail }}</pre>
        </template>
      </el-table-column>
      <template v-for="(item, index) in cptColumn">
        <el-table-column :key="index" :prop="item.prop" :label="item.label" />
      </template>
      <el-table-column label="操作" fixed="right">
        <template slot-scope="scope">
          <el-popover placement="bottom" :ref="scope.$index">
            <p>你确定要删除该条记录吗?</p>
            <div style="text-align: right; margin: 0">
              <el-button
                size="mini"
                type="text"
                @click="$refs[scope.$index].showPopper = false"
                >取消</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="del(scope.row.uid, scope.$index)"
                >确定</el-button
              >
            </div>
            <el-button slot="reference" size="small">删除异常信息</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="query.page"
      :page-sizes="[5, 10, 20, 400]"
      :page-size="query.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="query.totalRow"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import toolBar from "@/components/common/toolBar";
import curd from "@/mixins/curd";
const CURD = new curd({
  url: "/sys/monitor/exceptionLog/"
});
import { sendJSON } from "@/utils/request";

export default {
  components: { toolBar },
  mixins: [CURD],
  data() {
    return {
      // 列表配置
      // detail
      tableColumnConfig: [
        { id: 1, label: "接口路由", prop: "actionKey", show: true },
        { id: 2, label: "原因", prop: "cause", show: true },
        { id: 3, label: "发生时间", prop: "created", show: true },
        { id: 4, label: "提示", prop: "msg", show: true }
      ],
      toolQuery: {
        username: undefined,
        actionKey: undefined
      },
      toolQueryRules: {
        username: [],
        actionKey: []
      }
    };
  },
  methods: {
    // 删除数据 - API
    del(uuid, index) {
      console.log("重载");
      let param = [];
      uuid instanceof Array
        ? (param = uuid.map(item => item.uid))
        : param.push(uuid.uid);
      sendJSON("/sys/monitor/exceptionLog/del/", param).then(res => {
        this.$refs[index].showPopper = false;
        this.$message.success(res.msg);
      });
    },
    // 表格查询--条件
    resetForm() {
      this.$refs["toolQuery"].resetFields();
    }
  }
};
</script>

<style lang="scss">
@import "@/styles/base/index.scss";
</style>
